/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.accountinfo.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.accountinfo.dao.AccountInfoDao;
import com.thinkgem.jeesite.modules.accountinfo.entity.AccountInfo;

/**
 * 用户注册Service
 * @author ljh
 * @version 2016-12-12
 */
@Service
@Transactional(readOnly = true)
public class AccountInfoService extends CrudService<AccountInfoDao, AccountInfo> {
    
    @Autowired
    private AccountInfoDao accountInfoDao;
	public AccountInfo get(String id) {
		return dao.get(id);
	}
	
	public AccountInfo validateUser(AccountInfo user) throws Exception {
	   // if(){}
	   List<AccountInfo> list = accountInfoDao.validateUser(user);
	   if(list.size()>1){
	       throw new Exception("数据个数大于1，数据重复");
	   }
        return list.isEmpty()?null:list.get(0);
    }
	
	public List<AccountInfo> findList(AccountInfo accountInfo) {
		return accountInfoDao.findList(accountInfo);
	}
	
	public List<AccountInfo> validateAccountInfo(AccountInfo accountInfo){
	    return dao.validateAccountInfo(accountInfo);
	}
	
	
	public Page<AccountInfo> findPage(Page<AccountInfo> page, AccountInfo accountInfo) {
	    accountInfo.setPage(page);
        page.setList(dao.findList(accountInfo));
        return page;
		//return findPage(page, accountInfo);
	}
	
	@Transactional(readOnly = false)
	public void save(AccountInfo accountInfo) {
	  //  accountInfo.setId(accountInfo.getId())
	    if(StringUtils.isNotBlank(accountInfo.getId())){
	        dao.update(accountInfo); 
	    }else{
	        dao.insert(accountInfo); 
	    }
		
	}
	
	/*@Transactional(readOnly = false)
	public void insert(AccountInfo accountInfo){
	    accountInfoDao.insertaccountInfo(accountInfo);
	}*/
	
	@Transactional(readOnly = false)
	public void delete(AccountInfo accountInfo) {
		super.delete(accountInfo);
	}
	
}